/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.jul.giftmanager.ui;

import com.alee.extended.panel.WebCollapsiblePane;
import com.alee.laf.combobox.WebComboBox;
import com.alee.laf.text.WebFormattedTextField;
import com.alee.laf.text.WebTextField;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author user
 */
public class AddGiftPanel extends JPanel
{
    
    private WebComboBox giftTypeCombo;
    private WebTextField giftDescrField;
    private WebTextField shopNameField;
    private WebFormattedTextField giftPriceField;
    private WebCollapsiblePane previousGifts;
    
    private ButtonsPanel buttonsPanel;

    public AddGiftPanel()
    {
 
        giftTypeCombo = new WebComboBox();
        giftDescrField = new WebTextField();
        shopNameField  = new WebTextField();
        giftPriceField = new WebFormattedTextField();
        previousGifts = new WebCollapsiblePane();
        
        buttonsPanel = new ButtonsPanel(ButtonsPanel.ButtonsPanelState.OK_BTN, ButtonsPanel.ButtonsPanelState.CANCEL_BTN);
        
        init();
    }
    
    private void init(){
        setLayout(new BorderLayout(5, 5));
        
        previousGifts.setTitle("Previous gifts");
        
        Box giftTypeAndDescr = Box.createHorizontalBox();
        giftTypeAndDescr.add(giftTypeCombo);
        giftTypeAndDescr.add(Box.createHorizontalStrut(5));
        giftTypeAndDescr.add(giftDescrField);
        giftTypeAndDescr.setBorder(BorderFactory.createTitledBorder("Type and Description"));
        
        Box shopAndPrice = Box.createHorizontalBox();
        shopAndPrice.add(shopNameField);
        shopAndPrice.add(Box.createHorizontalStrut(5));
        shopAndPrice.add(giftPriceField);
        shopAndPrice.setBorder(BorderFactory.createTitledBorder("Shop and price"));
        
        Box boxes = Box.createVerticalBox();
        boxes.add(giftTypeAndDescr);
        boxes.add(Box.createVerticalStrut(5));
        boxes.add(shopAndPrice);
        
        setBtnActions();
        
        add(boxes, BorderLayout.CENTER);
        add(previousGifts, BorderLayout.EAST);
        add(buttonsPanel, BorderLayout.SOUTH);
    }
    
    public void setAddBtnAction(Action addBtnAction){
        buttonsPanel.setOkBtnAction(addBtnAction);
    }
    
    public void setCancelBtnAction(Action cancelBtnAction){
        buttonsPanel.setCancelBtnAction(cancelBtnAction);
    }
    
    private void setBtnActions(){
        setAddBtnAction(new AbstractAction("Add")
        {
            @Override
            public void actionPerformed(ActionEvent ae)
            {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        });
        
        setCancelBtnAction(new AbstractAction("Cancel")
        {
            @Override
            public void actionPerformed(ActionEvent ae)
            {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        });
    }
    
    public static void main(String[] args)
    {
        BasicFrame frame = new BasicFrame();
        frame.getContentPane().add(new AddGiftPanel());
    }
}
